<template>
  <div class="lottery-wheel">
    <up-swiper :list="list1" @change="change" @click="click"></up-swiper>
    <view style="padding: 24px">
      <div style="margin-bottom: 20px">
        <up-button type="primary" text="商城" @click="goToMall"></up-button>
      </div>
      <up-button type="primary" text="体检"></up-button>
      <div>用户名：{{ userInfo.name }}</div>
      
    </view>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import { getList } from "@/api/shop/index";
import { wxPay } from '@/utils/wxPay';
import { alipay } from '@/utils/alipay';

import oneJpg from "@/assets/1.jpg";
import twoJpg from "@/assets/2.jpg";
import { useUserStore } from '@/store/user';
const userStore = useUserStore();
const { userInfo, clearUserInfo,setUserInfo } = userStore; 

// 使用 reactive 创建响应式数组
const list1 = reactive([oneJpg, twoJpg]);

// 定义跳转函数
const goToMall = () => {
  // 假设商城页面路径为 /pages/mall/mall，根据实际情况修改
  uni.navigateTo({
    url: "/pages/shop/home/index",
  });
};

// 模拟接口请求数据
const getListFn = async () => {
  try {
    const res = await getList();
  } catch (error) {
    console.error("请求失败:", error);
  }
};

// 微信支付
const handlePay = async () => {
  try {
    // 这里需要从后端获取支付参数
    const payParams = {
      timeStamp: '20250427',
      nonceStr: 'abc123',
      package: 'prepay_id=xxx',
      signType: 'MD5',
      paySign: 'xxxxxx',
    };

    // 调用封装的微信支付函数
    await wxPay(payParams);
    uni.showToast({
      title: '支付成功',
      icon: 'success',
    });
  } catch (error) {
    console.error('支付失败:', error);
    uni.showToast({
      title: '支付失败',
      icon: 'none',
    });
  }
};
// 支付宝支付
const handleAlipay = async () => {
  try {
    // 这里需要从后端获取支付宝支付订单信息
    const orderInfo = '这里替换为实际从后端获取的支付宝订单信息字符串';

    // 调用封装的支付宝支付函数
    await alipay(orderInfo);
    uni.showToast({
      title: '支付成功',
      icon: 'success',
    });
  } catch (error) {
    console.error('支付失败:', error);
    uni.showToast({
      title: '支付失败',
      icon: 'none',
    });
  }
};

onMounted(() => {
  console.log("页面加载完成");
  setUserInfo({
    name: "张三",
    age: 20,
    gender: "男",
  })
  getListFn();
});
</script>

<style scoped></style>
@/utils/request
